ARG BUILD_BASE_IMAGE
ARG NGINX_BASE_IMAGE=nginx:stable-alpine

FROM ${BUILD_BASE_IMAGE} as build-stage

WORKDIR /app

RUN sha256sum pnpm-lock.yaml > /tmp/lockfile.sha256

COPY . .

# lockfile validation
RUN if ! sha256sum -c /tmp/lockfile.sha256; then \
  echo "Error: pnpm-lock.yaml has changed. Please rebuild the base image."; \
  exit 1; \
  fi

RUN pnpm build

FROM ${NGINX_BASE_IMAGE} as production-stage

COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

# run this docker by:
# docker run --add-host=host.docker.internal:host-gateway -p 80:80 your-image-name
